package com.dkm.ec.sale.repository.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.dkm.base.core.helper.SpringHelper;
import com.dkm.base.db.persistence.dao.IQueryDao;
import com.dkm.biz.repository.AbstractRepository;
import com.dkm.ec.sale.domain.SalePrice;
import com.dkm.ec.sale.persistence.dao.SalePriceQueryDao;
import com.dkm.ec.sale.persistence.entity.SalePricePo;
import com.dkm.ec.sale.repository.SalePriceRepository;

/**
 * 对象功能:产品销售价格 Repository接口的实现类
 * 开发公司:SKG.COM
 * 开发人员:Yuki
 * 创建时间:2015-01-23 15:26:47
 */
@Repository
public class SalePriceRepositoryImpl extends AbstractRepository<String, SalePricePo,SalePrice> implements SalePriceRepository{
	  
	@Resource
	private  SalePriceQueryDao salePriceQueryDao;

	public SalePrice newInstance() {
		SalePricePo po = new SalePricePo();
		SalePrice salePrice = SpringHelper.getBean(SalePrice.class);
		salePrice.setData(po);
		return salePrice;
	}

	public SalePrice newInstance(SalePricePo po) {
		SalePrice salePrice = SpringHelper.getBean(SalePrice.class);
		salePrice.setData(po);
		return salePrice;
	} 
	
	@Override
	protected IQueryDao<String, SalePricePo> getQueryDao() {
		return salePriceQueryDao;
	}

	@Override
	public SalePricePo getByProdSkuType(String prodSkuId, String type) {
		// TODO Auto-generated method stub
		
		return salePriceQueryDao.getByProdSkuType(prodSkuId,type);
	}

	@Override
	public List<SalePricePo> findBySkuId(String skuId) {
		return salePriceQueryDao.findBySkuId(skuId);
	}

	@Override
	public List<SalePricePo> findBySkuIdNotDel(String skuId) {
		List<SalePricePo> salePricePos = new ArrayList<SalePricePo>();
		List<SalePricePo> salePricePosTmp = findBySkuId(skuId);
		if(salePricePosTmp != null && salePricePosTmp.size() > 0){
			for(SalePricePo salePricePo : salePricePosTmp){
				if(!"delete".equals(salePricePo.getType())){
					salePricePos.add(salePricePo);
				}
			}
		}
		return salePricePos;
	}
	
}
